import re

# 2、ip地址匹配
while 1:
    """
    A类0.0.0.0~126.255.255.255
    B类128.0.0.0~191.255.255.255
    C类192.0.0.0~223.255.255.255
    回环测试地址127.0.0.0~127.255.255.255
    """
    ip_address = input("请输入ip地址:")
    if re.search(r"^([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-6])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}",
                 ip_address):
        print("你输入的是a类ip地址")
    elif re.search(r"^(12[8-9]|1[3-8][0-9]|19[0-1])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}",
                   ip_address):
        print("你输入的是b类ip地址")
    elif re.search(r"^(19[2-9]|2[0-1][0-9]|22[0-3])(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}",
                   ip_address):
        print("你输入的是c类ip地址")
    elif re.search(r"^(127)(\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}",
                   ip_address):
        print("你输入的是回环测试地址")
    else:
        print("你输入的不合规范")
